package cn.minhx.mw.dtp.admin.types;

import lombok.*;

import java.io.Serializable;

@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Response<T> implements Serializable {

    private static final long serialVersionUID = -2474596551402989285L;

    private String code;
    private String info;
    private T data;

    @AllArgsConstructor
    @NoArgsConstructor
    @Getter
    public enum Code {
        SUCCESS("0", "成功"),
        ERROR("500", "失败"),
        ILLEGAL_PARAMETER("400", "非法参数"),
        ;

        private String code;
        private String info;

    }

    public static <T> Response<T> success(T data) {
        return Response.<T>builder().code(Code.SUCCESS.getCode()).info(Code.SUCCESS.getInfo()).data(data).build();
    }

    public static <T> Response<T> error() {
        return Response.<T>builder().code(Code.ERROR.getCode()).info(Code.ERROR.getInfo()).build();
    }

}

